package impl.gui.util;

import impl.util.UtilityAssertion;

import java.awt.Color;
import java.awt.Component;
import java.util.Collection;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;

public class UtilityAssertionRenderer extends DefaultListCellRenderer {

	private static final Color				SELECTED_NOT_SATISFIED		= new Color(0xFFAB00);	// light orange
	private static final Color				SELECTED_AND_SATISFIED		= new Color(0xFADF31);	// yellow
	private static final Color				NOT_SELECTED_AND_SATISFIED	= new Color(0xFADF31);	// yellow

	private Collection<UtilityAssertion>	uAssertions;

	public UtilityAssertionRenderer(Collection<UtilityAssertion> uAssertions) {
		this.uAssertions = uAssertions;
	}

	public UtilityAssertionRenderer() {

	}

	@Override
	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

		if ((this.uAssertions != null) && this.uAssertions.contains(value)) {
			if (isSelected) {
				setBackground(SELECTED_AND_SATISFIED); // satisfied & selected
			} else {
				setBackground(NOT_SELECTED_AND_SATISFIED); // satisfied & not selected
			}
			setOpaque(true);
		} else if (isSelected) {
			setBackground(SELECTED_NOT_SATISFIED); // not satisfied & selected
			setOpaque(true);
		} else {
			setBackground(Color.WHITE); // not satisfied & not selected
			setOpaque(true);
		}

		setToolTipText("Double-Click to Edit");

		return this;
	}

}
